package org.eden.karb.common.util;

/**
 * @author trsimoes
 */
public class TypeConversionUtils {

    /**
     * This method converts a value to the desired class type. Supported class types are: String, Integer and Boolean.
     *
     * @param value value to be set.
     * @param classType class type to convert.
     * @param <T> class type.
     * @return converted value.
     */
    @SuppressWarnings("unchecked")
    public static <T> T convert(String value, Class<T> classType) {
        T result = null;
        if (classType == Integer.class) {
            result = (T) Integer.valueOf(value);
        } else if (classType == Boolean.class) {
            result = (T) Boolean.valueOf(value);
        } else if (classType == String.class) {
            result = (T) value;
        } else if (classType == Long.class) {
            result = (T) Long.valueOf(value);
        }

        return result;
    }
}
